package algotithm.weekendrace.leetcode244.test2;

import java.util.ArrayList;
import java.util.List;
import java.util.TreeMap;

/**
 * @author 25068
 * @Date 2021/6/6 11:00
 */
public class Solution {

    public static void main(String[] args) {
        Solution solution = new Solution();
//        int[] nums = {1,1,2,2,3};
//        int[] nums = {5,1,3};
//        int[] nums = {7,9,10,8,6,4,1,5,2,3};
        // 45
         int[] nums = {20803,2597,1787,689,19370,47611,39097,20988,29482,25643,20532,26120,4127,4207,20798,39417,29876,7299,16389,14103,40489,35581,45102,30732,43374,23320,16980,12008,35495,13621,20141,13056,16147,23624,5333,18402,5860,49368,29354,5931,42731,37642,42171,22210,14905,25591,20106,2691,21447,12243,20758,37946,19845,16112,21911,6616,35667,40069,37945,39058,6033,16063,14429,1336,15976,26331,4741,17568,36124,4648,47787,4924,1410,41641,650,19060,49200,23540,32327,30726,10105,6615,32862,21502,5054,33376,43598,11354,11769,9802,9276,20958,20030,7005,46487,33709,39446,19235,8278,13549,9286,35750,47359,2082,20714,40864,44054,36239,48902,45194,13464,11676,19591,28354,35226,10348,3183,46847,43764,16207,16554,4222,44701,29275,28192,35997,16399,35480,28797,35263,29709,713,25934,22196,11241,16907,31837,1600,42366,27308,37396,1240,4085,45332,23262,38016,9063,38899,8201,9077,16982,18148,26071,36968,26286,11284,40138,5849,15305,31851,491,11638,34649,20791,32827,42523,28726,44992,41885,47935,14794,15623,20512,32446,45020,31381,14750,46718,27017,22083,36727,40062,47725,42822,18038,42364,14384,3159,4690,33535,42290,24163,10451,33531,13360,20435,19577,45388,19633,36197,24355,10826,45960,45959,48262,30460,38967,5569,8077,39722,33683,37437,24721,11553,10210,16424,27968,14262,37324,47160,49660,3417,32443,44672,25796,47000,41745,22806,25165,33755,10801,35667,47835,2668,34353,5925,16724,41187,6623,17533,48294,5487,9118,40430,43236,44999,45902,5375,29168,15794,25058,28372,26034,10798,21330,28714,8280,40790,31980,13895,7812,28264,39367,35000,26754,7740,43288,19365,18198,16268,24829,49125,36660,263,12442,34627,28756,37951,1379,2020,41126,39691,15876,17066,13541,11329,18664,9727,35543,13137,17907,20391,38387,49639,16442,44796,29256,11009,35742,23394,32166,27523,7983,13694,37392,25118,13424,18616,7088,1583,7738,37311,48973,867,35736,19426,44166,49878,47469,42559,8952,4928,32793,24493,37525,20399,28651,32967,44386,23385,49717,34629,21214,56,8120,28988,47053,29462,22952,19976,35344,26176,22241,47916};
//         58898
        //int[] nums = {42423,29564,19674,48768,28564,28877,26077,40801,35694,39862,8742,29965,39611,31334,25370,6948,21761,18184,41088,9249,17351,43180,2853,6202,10911,47986,43187,2336,296,21425,22148,2700,10606,27648,28779,40572,1135,28269,36010,37084,26329,8005,44537,25900,3727,1803,8939,15739,33094,31856,42556,25594,20572,8410,18905,40111,9125,37258,37101,9173,36309,9262,49757,9554,38565,15529,47616,13001,2010,13931,32092,36654,30014,23845,30782,41532,28056,34804,33,27528,15636,46572,24839,17473,40566,1757,34460,21232,7127,33637,16094,28081,16841,8469,34150,30657,37205,49963,35874,24079,16510,7938,48308,49048,48802,5973,46642,22929,26540,28961,23904,27648,44320,33195,28781,32749,24683,35179,1848,3140,31981,21144,15140,6758,1283,22933,5051,46880,11769,45379,31139,8042,15146,9485,30126,48574,4954,10992,41180,18293,49586,31028,45462,23919,12248,15273,2852,19158,42513,29068,35637,36309,29701,39014,18475,16104,725,19928,30812,9751,13006,12909,11896,20072,4724,16825,11047,25665,41094,38403,19818,48846,11855,29792,26092,44604,6130,23421,39559,23383,15119,188,35431,40475,10777,29794,40791,8243,18498,25344,9742,22080,22476,16423,210,9400,12332,16861,13968,41080,412,3797,42480,2383,30101,18648,14578,34307,49366,42083,7194,49081,5111,39558,9807,13304,11678,2047,28559,10281,11254,28835,21012,3393,29273,40549,32898,23437,46357,18806,37922,8365,35614,40371,34204,3455,15942,7451,29636,32220,15059,33684,20748,7313,43937,20050,9889,17461,41939,27511,17375,7524,1196,280,24298,32892,12064,3728,21448,10425,2775,2267,1931,17133,16233,2016,47526,19089,31604,47205,47316,39207,42259,32724,22137,38483,5860,13079,11479,23024,47076,49053,5852,24255,9466,23595,12706,30258,24819,29371,22723,40260,38477,5126,16173,15296,6233,15464,5777,47913,20463,34253,24235,5315,7999,38476,39152,23617,16343,36459,18585,41229,20296,8163,10971,46892,26645,13878,30404,8951,12907,5202,28436,4766,24977,10089,37380,15985,19757,16793,39439,33526,47534,37583,31390,25320,7690,7119,43249,23568,29773,31590,43200,25867,13916,38436,21856,9850,41109,17593,21310,41769,12837,39188,2959,43271,26374,17419,21099,7042,41362,8690,13374,24471,30828,41384,21271,36976,2829,3605,46490,30041,8791,29770,32699,33383,49451,13982,18226,16873,40326,10227,18618,7790,20827,14649,22391,20492,12875,49749,7966,27237,13828,27556,8719,33549,34818,5823,25469,1916,25292,9125,25815,22657,40528,49869,33834,25991,39466,9589,47985,43045,6111,44961,34295,15125,49437,13078,31879,30997,24818,46823,20817,16554,36530,582,34632,49410,34344,45818,48360,47962,17074,1586,24983,48530,34199,25770,9481,11175,40002,17012,6510,26658,7479,46289,31298,26478,3518,31969,5350,36965,5212,14582,22099,25288,40033,44540,43220,22512,23310,46727,43592,49411,16439,15832,26862,9004,49314,14508,44799,26286,40960,47644,3042,16142,12319,37217,9673,37172,22218,12281,7121,13649,27568,3447,33603,21789,35196,49561,47009,23688,22889,43255,46357,28619,14935,22968,24953,4674,14750,30672,8409,23388,41041,24168,6056,30348,33781,27395,24737,17228,4806,30003,30599,43568,9776,17280,46114,45568,931,34579,23745,27771,15494,23016,46116,30523,21719,28882,34051,49323,759,9488,47063,49748,15757,45328,6487,14766,17869,23935,14679,37022,12087,29152,23450,24104,45795,2553,46058,43970,11962,25476,34853,23156,22783,43368,36190,37433,26791,19808,33365,17057,30034,5383,3492,6786,36497,17661,48666,20293,13925,27986,36518,38367,13110,16109,18281,6019,27338,25706,44581,33162,18859,19161,39643,31832,6051,27064,14711,45893,13101,31563,7953,33730,23534,37256,49168,35631,5466,2049,5356,21183,16016,29007,5948,12631,2166,28921,8701,5609,44932,30864,4227,3275,9453,32387,8222,45185,32389,28579,31409,19295,744,39802,16391,35665,41533,7797,39132,5984,41034,34997,36634,40466,23937,2195,15288,35329,43688,36730,9930,1430,49276,24961,2748,8684,21856,43923,25112,36379,4757,39465,29520,20188,21488,13555,27982,31718,4199,24952,49833,16527,298,42580,43428,41183,6903,19797,47881,14421,37156,37888,24771,861,25655,4958,42988,38515,5904,15959,4102,27471,34532,29283,36256,20385,33061,2135,9420,32371,31798,40810,24093,9830,35892,7636,13525,17552,35521,926,32561,40987,43398,38611,29679,9439,9671,20721,26230,28935,17871,39696,30051,38786,24269,46260,26007,44199,40494,37711,5497,1433,14138,35992,14606,16158,39952,44046,22771,28397,36481,6299,5436,1918,15299,42346,21727,15733,47599,13154,34668,10734,35981,5508,33430,10580,4032,19683,41760,16422,38433,46498,44760,21877,22812,27770,24361,13490,98,40170,38091,32711,8579,11706,24977,131,11947,1100,17361,23979,14310,26668,43181,12401,15957,27403,43355,38450,13298,27220,37387,24871,2827,11212,38284,95,41098,13619,6576,3762,19082,9657,35866,25759,40000,23615,12059,38624,43557,11052,10709,33595,9643,32755,42278,5799,29326,11977,18872,17505,22922,29002,15883,37519,46178,2849,47939,14994,42672,14271,17618,15692,49041,46091,28197,48292,46739,18347,46943,15409,23576,32123,26929,13234,30050,33656,44308,34712,20681,3051,15240,14591,35374,10169,27748,8078,35652,4813,49903,27308,27907,33593,24965,39384,30024,6201,13280,3861,25606,13674,35729,45935,13829,28327,34443,48858,33445,46923,40334,33561,39539,30897,49307,24527,41949,6894,24668,41681,44431,49933,19265,33299,24087,20500,11522,27637,43514,35565,16150,12473,4923,14876,5602,16681,44710,27534,48545,14624,32269,42042,16775,2201,25819,22592,26315,30427,27319,13391,3576,18705,15228,9896,9372,22070,43184,43189,48813,35411,44363,19443,40025,38143,29584,27896,44162,19752,24517,48151,20527,16994,14898,29724,25844,48793,21606,2502,37901,13793,44648,6246,43220,41012,8937,16196,23042,9429,46944,32812,29295,49414,26156,16431,825,27309,20695,9377,20873,4535,13557,25318,13787,26210,40304,33441,36168,5910,44411,41778,30686,13852,7378,9087,24907,7325,25311,33920,38535,47561,49719,16064,30593,31650,35620,5364,10606,49424,382,23127,3684,37034,30118,8948,49497,32763,25148,13225,47633,12373,39522,4020,22296,12891,31373,18372,48874,11709,35922,32599,33125,48690,34582,27347,3152,10174,12606,666,20159,27449,45483,4684,12090,42449,1570,24687,18968,33450,9728,18689,9030,11190,19554,33334,15322,43732,20214,29397,40809,13858,33322,12739,45991,3415,13492,39707,24657,21479,23360,43208,25108,2893,44094,25912,5792,10305,32339,10095,23103,20257,11849,2635,45435,31591,30215,23357,22601,22759,40608,33780,48817,35377,14267,35633,8766,15824,27167,43835,4144,15723,16852,19629,35065,30393,21919,41246,29022,1070,32233,46096,31976,8696,1744,27858,25384,12260,18730,36743,45154,24756,12490,38765,44067,26166,48545,45737,1686,15952,42123,31729,22288,23756,29174,20282,5161,3801,33998,20668,10306,8915,3470,23712,30966,15841,39959,42171,46562,2789,2279,948,31283,30059,30607,28136,15918,26594,11525,6799,15909,18671,19950,15083,1643,6914,13469,28148,43540,18708,32494,49439,18376,20094,7189,41356,30562,9099,18426,20510,20408,38470,35332,22259,2334,19466,12889,16723,30446,32946,47419,34800,14595,49419,221,20527,29925,7268,4229,27950,23151,16537,2761,9176,45382,45874,42587,33079,20011,24555,22505,26164,11731,3437,30677,21382,10712,39405,15039,31471,10680,40755,27960,35778,26096,7175,20469,49868,5985,40165,30086,10655,38613,28524,32147,41907,9186,48578,4137,2034,36581,45826,34994,31410,37424,39303,35295,8681,15649,2919,35261,19764,27135,44813,37494,30360,16853,37337,22853,36183,21831,33830,23950,37149,2223,11804,27999,14591,32545,41405,24340,43106,16586,47570,48673,49546,15936,4330,40433,17014,19181,33664,2216,19241,31337,31572,46310,10724,6063,44111,38473,34762,35875,13049,3284,37468,38101,34268,22241,18742,4330,36392,39540,14801,38800,42986,11113,9524,44620,47121,28392,41362,40138,20575,41500,46489,13089,39702,30475,43710,12130,58,13253,3321,1150,5012,25352,23694,28645,12301,10568,323,27912,2074,16115,4066,25749,7378,24223,24530,36216,39379,8759,24957,34299,41860,6160,48804,20864,32112,41425,252,30651,15398,26457,36811,5242,28379,39408,38655,24642,1249,22559,33729,19217,15190,26109,32536,26491,24198,3266,4045,26717,39719,28072,38492,10303,45273,9508,21667,12495,9243,32232,27088,20549,49415,391,23955,24421,23760,47818,5250,49275,25152,8636,46864,42283,2376,9274,3238,48031,20233,17335,21820,2659,5189,8366,8998,15725,20808,13816,49438,10319,29093,13049,26774,24410,8630,20393,38902,12018,30156,1618,37626,11681,48079,41088,7985,2074,48951,9233,27148,43238,19129,33618,49450,13930,3732,4643,39502,34369,33661,35395,46512,27796,48000,17598,45378,30805,36633,28902,30512,42385,37985,40590,5344,37028,22484,6969,19664,15024,2917,15570,7601,13474,11739,43002,49312,25751,49371,26555,41486,8441,37010,15147,36841,42084,13544,31971,45225,38513,42083,10049,44948,48572,41178,49635,7644,25111,29159,23525,44001,1376,39455,31550,41779,31979,3841,16334,39980,18608,11366,33196,39907,30729,4471,49097,20837,5670,17108,45672,34084,19792,44166,8498,35693,41832,3890,20671,5191,9656,32769,45877,8538,11316,43585,1605,40374,35066,45,4018,4531,49482,35374,23662,31279,3148,44965,34392,42460,44074,34985,5078,30121,29783,37149,44096,1158,18061,23324,29402,5267,22752,4219,11461,11607,49610,37588,286,37817,25865,12691,37306,43892,14676,10129,31887,8044,22800,34315,44102,32162,39104,6750,47166,40815,35410,44575,11588,32776,20241,6378,19659,5790,40686,7636,37451,21120,35222,28925,37740,48471,38074,18902,28820,18913,49605,33181,28784,34910,30255,38629,9796,19919,38167,17667,5080,43727,18752,2222,37236,25969,46967,8522,32088,38203,42868,47860,47004,21198,43676,17196,7965,37871,18968,28558,14534,15989,25596,35424,38282,4780,26359,44184,8283,16633,2764,44694,16618,15410,22210,5282,16939,24998,6839,8615,15843,31861,21238,30298,26662,5325,33415,38160,30701,2357,28475,13024,25826,37074,37410,44589,17071,40414,40464,49610,8389,8735,24751,3623,1174,42133,3516,28887,256,22673,33751,29192,21404,12167,45777,43621,13701,47564,28885,40800,14042,43349,13116,25510,21757,46432,29024,18283,17981,10589,19676,43908,5725,40730,39833,35858,4609,34676,40522,31429,37409,38890,35673,15971,6266,32746,7868,29487,33138,35715,10942,7394,45696,42292,21281,34196,46836,24731,38129,14694,34139,6281,29540,14983,7337,5723,31207,16501,37762,33702,19820,1302,21871,39614,44652,25188,15995,28264,10009,32872,37087,29410,4451,31181,16812,26837,48388,35421,37816,36429,4452,46160,8013,25182,7765,17526,24787,2107,6032,35671,22557,4896,25693,44227,30794,31412,48914,43937,42241,42032,10299,26224,2781,17133,26111,44259,25681,25257,29657,1021,46763,44347,15908,35225,8568,4802,32696,26485,13732,7031,45175,47000,30271,12872,26493,41608,26623,28487,1685,18399,1436,2857,31876,48523,27423,8571,39029,11542,48739,12390,33056,24660,18604,5192,35900,2770,27081,46579,9579,30605,10420,19471,2603,42604,19708,38350,19182,2056,40275,34306,21460,19264,2088,31954,5689,10712,48515,41486,44410,49306,39027,25120,46043,41301,32313,17296,29437,1473,27523,2292,19332,3220,22743,13073,22433,11855,16044,9063,5966,2667,6181,10128,20138,20707,32309,38826,37593,39264,31066,1407,25233,37858,35652,24861,15371,48217,34433,9328,36050,6853,27341,36251,25281,14664,36504,554,39071,37453,36854,20727,26875,25457,36572,41244,43647,14318,8696,28648,11577,7169,37209,7382,47291,19521,11507,23055,30967,32610,34530,10519,38539,17519,41936,45903,15722,17303,4622,46967,33373,21327,16044,42950,39980,36450,14388,17220,10583,41741,8592,3723,30331,23371,8453,40513,16288,19955,48245,2717,27811,29275,32294,48922,3478,11376,36717,24789,43725,44607,32663,42856,47393,20484,20111,18233,10377,23443,43760,34766,48867,47769,24160,6079,49662,28132,15876,45932,23810,6189,23094,15917,46731,4328,24021,44334,35016,43429,43117,44990,20358,2817,37331,23208,33973,820,25237,43220,6292,147,150,37606,11735,30288,7149,14191,24455,4353,33557,9041,26260,12079,28693,39763,6210,33784,17852,46103,31406,11939,24544,43162,9896,7926,42491,8747,5092,41918,25962,10569,11955,14708,18817,7014,3228,39486,14267,415,39003,45584,14108,821,41680,28982,45471,12562,40258,24656,19467,9784,22236,24369,40507,24817,7091,40035,40366,12726,22236,535,27690,29252,47324,12657,10841,1452,32833,17261,30691,15249,5406,4272,14092,39362,47436,9189,16295,15698,46890,35767,23663,34115,34222,1223,37476,33641,12968,29481,2110,6471,11422,26940,8425,44112,31839,33118,15056,15714,3687,24351,11075,35944,43571,10701,28274,35313,16127,17623,22698,49205,41614,39229,35228,13300,19346,38864,15518,6710,35749,2698,21607,20045,36456,11704,48487,8252,27083,20824,35713,18640,39246,1526,42347,34985,16240,1879,20841,31268,3325,13413,26169,6482,28833,46540,41401,26544,32378,35311,36151,13268,49538,29329,7023,44508,41839,12618,49936,49497,42707,11495,41651,16893,39634,46367,17216,494,4410,43760,43630,25325,1202,12542,33107,21809,17954,41740,37087,13441,31315,36634,9698,29638,2720,24927,33438,25875,26346,3617,41983,3962,18956,23183,15360,47657,12870,30126,36606,30813,30756,2473,35897,12525,7722,21063,46841,19628,28049,47995,16306,45992,48532,10298,18164,38570,17461,44840,36028,38328,24546,7019,43104,45209,23566,27843,33191,27788,29570,31397,14646,6441,11586,33884,39029,29570,40690,30609,3730,6719,5534,26288,26140,49391,17432,12544,42917,44566,32256,37579,43873,44148,23438,39005,24625,35358,33168,7399,38657,814,15557,32023,25255,17237,40205,17480,5588,10625,25820,6426,3367,13896,22600,11798,11406,19056,36979,7559,15351,42435,972,27413,18882,10284,9557,37985,8747,39846,21478,35919,12469,8064,21912,43042,32345,13240,20471,40907,45888,2568,47002,39605,12505,11555,21645,43130,33158,12485,12598,42517,27776,7260,21382,38165,37240,46159,17659,11704,172,49376,41790,45110,46937,32991,19875,25085,35338,25296,26495,4164,20779,22017,8836,16984,17541,39781,28927,10465,30222,12552,25145,30758,6126,28988,46543,7982,36587,12256,16848,20288,26892,19287,48677,19569,13067,23404,42618,45880,8537,43936,39132,49363,14091,35352,42171,6825,28254,14207,17171,49543,35011,35047,43524,41308,15516,8650,43563,36973,43391,4463,22099,3416,48478,49690,29223,16430,41817,46147,3838,43504,3767,39590,16109,2404,48672,23214,6092,11079,43898,11832,12555,12290,42249,39966,2843,33112,40124,40187,47037,41123,33861,756,44522,26775,32383,41109,3928,35467,15717,34212,15758,43363,7073,21302,27939,11575,2111,33776,40465,25327,19977,23195,2017,30117,22383,25310,28692,32696,31029,23284,47440,42933,10728,28654,3998,44293,46052,34403,21547,16989,37272,3146,2038,25169,10089,31136,12880,25562,35591,39964,47667,30636,11697,14834,33707,3908,40297,10777,26947,29707,49134,38148,42232,47256,68,12981,3043,37124,40657,25987,4830,46224,34495,26364,382,9278,14748,45120,26177,22226,13643,6712,42908,25496,20759,2152,39227,5024,13237,22945,23068,45726,2800,42328,28016,38790,20038,28534,19219,42655,33089,10542,49130,11059,33697,37128,8793,43106,45243,827,37372,46,28559,14098,14557,28769,6295,495,28593,10441,36002,18872,33844,48171,30284,48442,43664,12183,40620,37528,25602,12589,46412,19010,20764,7531,42283,7754,36817,7772,31711,3366,36405,25169,23297,36676,3623,6927,30410,17510,3814,37911,21478,47416,28678,8202,20355,30030,3134,8305,18886,34831,7430,38895,8016,42390,5332,28074,28213,33309,5618,27715,23327,36674,38410,11035,45941,37737,32283,32721,47024,42534,46204,39823,33280,27174,19245,49251,30276,30621,15857,13691,38618,35231,12612,8655,4074,18157,48148,903,28952,29393,43718,11499,13660,18959,35755,19838,9526,5569,12084,34778,5914,43214,10921,11174,26694,11026,13975,49835,27640,16569,22236,43251,10051,36525,15208,27170,21515,48778,49994,750,49401,49131,47593,15134,11185,41426,19167,3728,7344,14794,40958,44371,1989,27952,38708,294,33937,2213,11412,44939,39418,1242,35216,28807,47511,48139,27753,41220,9606,23869,26275,14780,49657,44200,36910,32464,47009,36597,41605,18306,7996,32906,49045,18893,1546,19228,41475,34458,49930,4057,18754,3601,6048,24272,23332,7512,43801,33035,29505,17999,46539,2254,3647,36181,17897,22195,22852,16067,18390,32124,17324,49842,49437,4431,15032,26757,24946,30797,10627,40237,27061,30033,28473,14525,29923,33644,41466,5367,48198,33273,25857,24898,12365,13165,40636,8730,2461,41053,9374,29938,23019,23102,44715,6148,16611,15794,20951,20302,1162,44138,16723,28481,29823,17397,42733,22336,47065,46255,5455,46163,48837,814,17610,27896,45762,10135,15152,39151,24341,40529,25239,321,15486,35723,46545,47401,11482,14552,43799,7856,12579,6174,12655,47852,41246,15133,2781,27133,47968,22409,9445,47342,44191,827,30557,41522,39127,14190,3969,40630,2251,46633,49920,6560,2365,12298,23167,4125,24676,37455,39139,14217,44546,20868,25634,19074,11243,38932,19145,20227,18301,38162,23751,14964,14432,7825,48224,24766,9327,23595,18616,23044,39126,34530,38787,23348,3455,34337,3727,5921,28449,22210,34444,23375,35414,15778,19997,34047,18716,25314,33861,35742,21148,10936,9749,35175,6568,43289,40024,9947,43132,14582,45805,19825,28483,27651,17273,33017,41173,40921,43526,42006,23972,20251,29006,29315,3700,29815,36722,26885,17,37826,8112,19523,40385,32841,11880,42147,4776,7390,15674,23781,29362,24017,43428,18972,9848,18186,43927,6710,47728,8451,44551,32041,21714,35887,15214,23091,2474,3649,7706,12048,32569,29811,44991,33324,6114,26620,4007,37581,47951,9828,4740,19917,734,41300,38975,30076,15895,40240,48356,15133,14152,47039,8553,36323,38049,26600,8663,38137,45556,9763,10257,23185,44119,3669,24380,1922,48325,44676,43570,32524,29621,6033,2293,45079,46192,29361,9000,25067,42391,17423,3964,2493,34388,2490,12079,14565,40208,47186,18487,34526,7782,49810,37759,19984,12104,2341,38873,7022,31359,9739,49870,16660,7555,36376,5510,44401,21558,8694,15107,14902,22039,38778,28857,22835,37117,46824,43867,740,37246,4314,47992,17896,37421,36064,12122,948,48972,35823,42972,49311,24236,39009,19291,36621,11155,40966,748,32146,36129,10983,23768,37818,33036,23945,45293,36207,28135,32737,30941,22584,26758,6410,44503,4958,6471,14996,21290,13523,2468,46016,39523,38505,46546,3909,38867,23074,14511,49575,40070,27341,24695,3379,44011,3350,28350,49941,47436,38634,49183,18199,43289,37985,24574,45756,4797,6778,21536,11767,22807,25455,30594,10411,47808,11485,27485,46230,30930,12399,1733,32786,49100,10433,12980,43697,42025,12028,43718,5303,39166,48483,48912,40101,40622,1724,5861,12502,29679,16875,3989,26117,17668,27638,48844,15525,29618,8135,4559,13890,13624,14264,2013,11480,26992,41219,32037,28815,21706,11661,44212,12554,27555,6083,24981,45533,23847,23721,5660,33899,44587,30136,34710,44429,36546,45290,496,12845,18288,23383,23551,1833,12296,16119,27872,21274,24190,44079,39746,28871,30332,46727,48742,47123,7233,48080,36175,49970,2333,41814,13725,22442,5069,28264,16559,46166,43950,15961,3800,20388,6166,20392,36981,9667,28198,23678,33917,5449,20076,4736,28996,31331,10748,15695,37507,69,34951,1952,13012,13822,21489,39148,6010,38191,25542,26887,33400,42989,24785,43714,37341,22417,24819,28704,18464,33723,23365,12479,9180,35292,41260,19534,35543,6211,47811,31941,22953,25985,47099,12109,43270,2165,5566,32268,44845,3925,25735,10141,38019,48311,8984,12022,33643,4516,48581,25792,36640,12664,34135,25704,23275,45588,38507,27148,11409,26666,38886,17986,15302,48549,38723,24569,40086,34051,531,49407,45609,19186,18853,32843,17538,9558,13490,30515,2549,17757,7527,47345,44165,5749,3370,41758,42596,4361,32625,8865,31901,30282,40387,25522,14815,44626,3480,27205,11113,3455,19041,29772,2942,10181,32978,42777,42514,12508,13638,41132,45883,10571,14004,8288,1239,24633,41186,1131,49155,26554,40140,24110,23647,21859,9915,21114,21152,34850,45145,22252,41365,3851,21220,29706,10638,6090,978,47502,1750,31945,45049,6795,12346,25552,40766,34527,26979,39863,7189,17194,33854,28593,2879,49216,30088,14189,2864,36194,188,45872,47765,19227,27555,4163,21945,22630,38379,26316,4040,39749,43072,17643,8629,13421,858,10522,29261,3488,40100,37148,26963,45514,7154,36131,2143,34684,11035,46521,42698,43345,42290,30208,4261,756,35957,564,9234,14799,192,34851,2056,33438,42188,38802,44831,15406,39143,46118,28535,46599,7069,31927,24439,21879,10747,47304,43127,13940,16006,5502,42948,14259,10828,45252,19733,6067,5160,45515,13653,8468,48821,4936,29480,49342,16908,23669,16197,9239,11284,38322,15665,27825,4893,24369,34643,34957,11392,3947,35417,44441,2842,18294,430,36484,48886,38391,31283,27280,12584,38806,7372,23119,46589,21960,32826,33022,38745,48887,39510,49393,43407,49899,16939,10792,48527,37898,18645,19455,31948,33392,21244,33040,42344,40166,28037,7288,3147,4263,4172,20440,40294,27591,42049,25325,24398,21516,37774,5877,46204,9623,36537,37129,48811,28878,33034,27368,14740,36321,16586,48660,27166,22039,42966,20436,11333,2744,7398,47145,6588,28690,7974,47528,31157,49728,46015,22867,18051,7839,20595,25031,7972,10770,34054,48347,34952,29389,47883,33102,5811,32654,22447,36936,8138,21085,6415,6471,36107,15969,32462,15895,31845,22089,2910,10913,4046,1021,28084,44878,21733,19973,36319,40797,48209,16114,23284,9578,44938,49130,4637,41434,12348,2287,11548,49839,46446,23425,28567,44548,17265,13767,10554,13730,26576,49544,34529,12142,11461,15667,30456,9382,40300,40644,40013,18466,36960,21245,10548,44361,20937,35575,37603,40761,18473,15783,12792,10932,18479,2097,9321,8530,1685,28595,3416,22945,47052,29423,9490,28048,14157,10280,35709,23484,48156,11414,48361,4491,47044,17178,24346,22000,3171,33982,19999,44880,10196,47311,39379,31492,42329,3398,30510,41404,27330,40186,5746,1195,539,2843,1058,1904,14099,24204,13352,29525,2897,46095,3253,14523,19547,13150,36618,11719,12649,37538,13012,24339,34832,14083,47716,8880,37201,46526,6558,20591,10508,35724,41092,30452,43329,32708,1516,35546,31355,4442,856,29769,20960,37534,23523,22661,26965,9383,46137,8142,7142,30332,43095,21328,10907,42390,4602,25234,1372,33032,29099,16,43589,49512,39751,8834,19425,18428,19917,3915,31199,31129,4031,37243,9789,60,32578,39056,26986,2429,15953,7636,47815,25465,44035,35247,34345,1839,38177,20163,448,1474,15802,34786,46873,41715,25234,18241,41145,23848,47500,360,13972,40344,47235,28108,13999,47324,29661,32923,3233,8480,35465,40928,17726,42192,2240,6355,25969,6258,3153,32430,39233,32107,9803,7299,45887,32017,16417,11945,3945,7104,34899,30448,4700,12009,22105,30534,49243,35049,10296,46556,31959,48137,24538,16851,45121,19499,31714,11288,43275,19789,34249,1907,11557,15937,6862,48538,25498,5056,7944,19356,45896,6475,16635,43399,14467,11372,49982,44995,23690,7016,29471,6528,21164,34087,35778,4344,29264,38190,28468,5716,34456,39419,7341,30657,39249,30966,16802,24991,30483,30993,24834,25144,6386,24646,21874,40990,46005,688,4530,11385,32270,28220,1953,5603,47953,25448,44935,33243,39201,21640,2600,49990,1762,33032,42792,57,29563,49038,34732,11481,29653,19835,46792,26638,5072,33207,47580,40356,13402,27987,20851,32253,28154,42331,25659,43612,41094,2023,37361,46405,47362,34673,42014,36574,6694,11210,26555,35769,10152,16692,14098,32419,48692,9021,22515,47430,47668,35939,41853,6759,10367,39043,46244,42375,32299,1268,20394,2474,43299,35793,6397,17639,32304,47191,10296,26938,16477,23058,19311,21219,16595,12166,34342,38709,14018,40874,40598};
        int res = solution.reductionOperations(nums);
        System.out.println(res);
    }

    public int reductionOperations(int[] nums) {
        int res = 0;
        int min = nums[0];
        TreeMap<Integer, Integer> map = new TreeMap<Integer, Integer>();
        for (int i = 0; i < nums.length; i++) {
            map.put(nums[i],map.getOrDefault(nums[i],0) + 1);
            if (nums[i] < min) {
                min = nums[i];
            }
        }
        int x = 0;
        List<Integer> list = new ArrayList<Integer>(map.keySet());
        for (int i = list.size() - 1; i >= 1; i--) {
            x += map.get(list.get(i));
            res += x ;
        }
        return res;
    }

}
